package com.yz.group1.group_1.controller;

import com.yz.group1.group_1.entity.UserBook;
import com.yz.group1.group_1.service.UserBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/bookings")
public class UserBookController {
    @Autowired
    private UserBookService userBookService;

    @PostMapping
    public UserBook createBooking(@RequestBody UserBook userBook) {
        return userBookService.createBooking(userBook);
    }

    @PutMapping("/{id}/cancel")
    public boolean cancelBooking(@PathVariable Long id) {
        return userBookService.cancelBooking(id);
    }

    @GetMapping("/patient/{patientId}")
    public List<UserBook> getPatientBookings(@PathVariable Long patientId) {
        return userBookService.getPatientBookings(patientId);
    }

    @GetMapping("/doctor/{doctorId}")
    public List<UserBook> getDoctorSchedule(@PathVariable Long doctorId, @RequestParam String date) {
        return userBookService.getDoctorSchedule(doctorId, date);
    }

    @GetMapping("/{id}")
    public UserBook getBookingDetail(@PathVariable Long id) {
        return userBookService.getBookingDetail(id);
    }
}